package com.example.jetpacker.lifecycles

import android.util.Log
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent

/**
 * 主动获取生命周期
 * lifecycle.currentState返回的生命周期状态是一个枚举类型，一共有INITIALIZED、DESTROYED、CREATED、STARTED、RESUMED这5种状态类型
 */
class MyObserverTwo(val lifecycle: Lifecycle) : LifecycleObserver {

    @OnLifecycleEvent(Lifecycle.Event.ON_CREATE)
    fun activityOnCreate() {
        Log.e("MyObserverOne","onCreate")
    }

    @OnLifecycleEvent(Lifecycle.Event.ON_START)
    fun activityOnStart() {
        Log.e("MyObserverOne","onStart")
    }

    fun getLifecycle() {
        lifecycle.currentState
    }

}